//
//  SSMineController.m
//  电商项目
//
//  Created by Esther on 2017/2/18.
//  Copyright © 2017年 Esther. All rights reserved.
//

#import "SSMineController.h"
#import "SSMineTableView.h"
#import "SSMineHeadView.h"
#import "SSRegisterController.h"
#import "SSLoginController.h"

@interface SSMineController ()
@property(nonatomic, strong) SSMineHeadView *headView;
@property(nonatomic, strong) SSMineTableView *contentTable;


@end

@implementation SSMineController

- (void)viewDidLoad {
    [super viewDidLoad];
    // 头部
    [self setupUI];
    
}

- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    [_contentTable reloadData];
    [_headView reloadHeadView];
    
}

#pragma mark -
#pragma mark - 搭建界面
- (void)setupUI{
    self.view.backgroundColor = [UIColor ss_colorWithRed:242 green:242 blue:242];
    
    #pragma mark - 添加子视图
    [self.view addSubview:self.contentTable];
    
    #pragma mark - 约束
    __weak typeof (self) weakSelf = self;
    [_contentTable mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.right.bottom.equalTo(weakSelf.view);

    }];
    
    
}

#pragma mark -
#pragma mark - 懒加载
- (SSMineHeadView *)headView{
    if (!_headView) {
        _headView = [[SSMineHeadView alloc] initWithFrame:CGRectMake(0, 0, [UIScreen ss_screenWidth], 125)];
        __weak typeof (self) weakSelf = self;
        _headView.registerBlock = ^(){
            SSRegisterController *registerController = [[SSRegisterController alloc] init];
            [weakSelf.navigationController pushViewController:registerController animated:YES];
        };
        
        _headView.loginBlock = ^(){
            SSLoginController *loginController = [[SSLoginController alloc] init];
            [weakSelf.navigationController pushViewController:loginController animated:YES];
        };
    }
    return _headView;
    
}

- (SSMineTableView *)contentTable{
    if (!_contentTable) {
        _contentTable = [[SSMineTableView alloc] initWithFrame:CGRectMake(0, 0, [UIScreen ss_screenWidth], [UIScreen ss_screenHeight]) style:UITableViewStylePlain];
        _contentTable.tableHeaderView = self.headView;
        __weak typeof (self) weakSelf = self;
        _contentTable.logoutBlock = ^(){
            [[NSUserDefaults standardUserDefaults] removeObjectForKey:@"ISLOGIN"];
            
            [weakSelf.contentTable reloadData];
            [weakSelf.headView reloadHeadView];
        };
    }
    return _contentTable;
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
@end
